package org.icress.fusion.b2b
import org.icress.fusion.shiro.User
import org.apache.shiro.SecurityUtils

class BomService {

    static transactional = true

    def save(bomInstance) {
        //get user
        def currentUser = User.findByUsername( SecurityUtils.getSubject().getPrincipal() )
        
        //set instance params
        bomInstance.createdBy = currentUser
        bomInstance.lastModifiedBy = currentUser
        bomInstance.owner = currentUser
        
        //validate
        bomInstance.validate()
        
        //save
        bomInstance.save(flush: true)

    }
    
    def update(bomInstance) {
        //get user
        def currentUser = User.findByUsername(SecurityUtils.getSubject().getPrincipal())
        
        //set instance params
        bomInstance.lastModifiedBy = currentUser
        bomInstance.lastUpdated = new java.util.Date()
        
        //validate
        bomInstance.validate()
        
        //save
        bomInstance.save(flush: true)
    }
}
